package com.example.user.controller;


import com.example.user.common.Result;
import com.example.user.entity.Order;
import com.example.user.request.CartRequest;
import com.example.user.service.OrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@CrossOrigin(origins = "http://localhost:8080")
public class OrderController {


    @Autowired
    private OrderService orderService;


    /**
     * 生成用户个人订单
     * @param cartRequest
     * @return
     */
    @PostMapping("/createOrder")
    public Result createOrder(@RequestBody List<CartRequest> cartRequest) {
        System.out.println(cartRequest);
       // Result result = orderService.createOrder(cartRequest);
        return null;
    }

    /**
     * 用户个人订单查看
     */

    @GetMapping("/getOrderPage")
    public Result<PageInfo> getOrderPage(@RequestParam("userId") Integer userId,@RequestParam(defaultValue = "1") Integer pageNumber, @RequestParam(defaultValue = "10") Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        List<Order> orderList= orderService.getOrderPage(userId);
        return Result.success(new PageInfo(orderList));
    }

}
